// pages/index03/index03.js
const util = require('../../utils/util.js')
import Bmob from '../../utils/dist/Bmob-1.7.0.min.js'
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    shuju:[],
    nu :20,
    shuru1:[],
    arr:[],
    arr1:[],
    showModal:false,
    time1:[],
    time2:[]

  },
  //页面跳转
  tiaozhuan:function(e){
    let item = e.currentTarget.dataset.item;
    let _str = JSON.stringify(item)
    wx.navigateTo({
      //url: e.currentTarget.dataset.path,
      url: '../search1/search1?shuju=' + _str,
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var shuju = []
    var time1 = []
    const query = Bmob.Query("hyh");
    query.order("-createdAt");
    query.limit(20);
    query.find().then(res => {
      console.log(res,"789")
      shuju = res
      /*  for (var i = 0; i < res.length; i++) {
         shuju.push({
          dataId:res[i].dataId,
          createdAt:res[i].createdAt,
          objectId:res[i].objectId,
          pic01:res[i].pic01
         })
       } */
      this.setData({
        shuju: shuju
      })
      console.log(res[0].createdAt)
      for(var i=0;i<res.length;i++){
        var time = res[i].createdAt.replace(/\s[\x00-\xff]*/g, '');
        time1.push(time)
      }
      
      this.setData({
        time1: time1
      })
    });


    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   

  },
  ok:function(){
    this.setData({
      showModal:false
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      nu:20
    })

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var shuru1 = [];
    var arr = [];
    var arr1 = [];
    var time2 = [];
    var nu = this.data.nu
   
    const query = Bmob.Query("hyh");
    query.order("-createdAt");
    query.limit(20);
    query.skip(nu);
    query.find().then(res => {
      console.log(res)
     /*  shuju1 = res
      console.log(shuru1,8)
      this.setData({
        shuju1: this.data.shuju1
      }) */
      if(res==''){
        this.setData({
          showModal:true
        })

      }else{
      var arr = this.data.shuju;
      var arr1 = res;
      console.log(arr,89)
      console.log(arr1,90)
      arr = arr.concat(arr1);
      console.log(arr,91)
      this.setData({
        shuju:arr
      })
      
      console.log(res[0].createdAt)
      for(var i=0;i<res.length;i++){
        var time = res[i].createdAt.replace(/\s[\x00-\xff]*/g, '');
        time2.push(time)

      }
      console.log(time2,"时间")
      this.setData({
        time2: time2
      })
      var time1 = this.data.time1
      var time1 = time1.concat(time2)
      this.setData({
        time1:time1
      })
      }
    });
    
    this.setData({
      nu: nu + 20
    })
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})